#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setFixedSize(1280,720);
    r=new regwin;
    connect(ui->loginbtn,&QPushButton::clicked,this,&MainWindow::login);
    connect(ui->regbtn,&QPushButton::clicked,this,&MainWindow::reg);
}

void MainWindow::reg()
{
    delete r;
    r=new regwin;
    r->show();
}

void MainWindow::login()
{
    qDebug()<<1;
    QString name=ui->nameInput->text();
    QString pw=ui->pwInput->text();
    QString names[1000],pws[1000];
    qDebug()<<1;
    QFile file("pw.t");
    file.open(QIODevice::ReadOnly | QIODevice::Text);
    qDebug()<<1;
    QTextStream in(&file);
    int endd=0;
    qDebug()<<1;
    while(!in.atEnd())
    {
        names[endd]=in.readLine();
        pws[endd++]=in.readLine();
    }
    qDebug()<<1;
    for(int i=0;i<endd;i++)
    {
        if(names[i]==name&&pws[i]==pw)
        {
            this->hide();
            qDebug()<<2;
            illcases *p=new illcases(name);
            qDebug()<<2;
            indexw=new class index;
            qDebug()<<2;
            indexw->setillcases(p);
            qDebug()<<2;
            indexw->show();
            return;
        }
    }
    qDebug()<<1;
    ui->error_label->setText("用户名或密码错误");
}

MainWindow::~MainWindow()
{
    delete ui;
}
